366B - Dima and To-do List - CodeForces Solution


brute force implementation *1200

Please click on ads to support us..

Python Code:

from heapq import heappush,heappop
from collections import deque

t = 1
for tc in range(1,t+1):
        n,k = map(int,input().split())
    a = list(map(int,input().split()))
        
    ans = float("inf")
    ind = -1

    for i in range(k):
        j = i
        s = 0
        while j<n:
            s+=a[j]
            j+=k
        if ans>s:
            ans=s
            ind=i
    print(ind+1)

C++ Code:

#include <bits/stdc++.h>
#define Bankai ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
int main() {
    Bankai
    int n,k,a;
    cin>>n>>k;
    vector<int>sum(k);
    for(int i=0;i<n;i++){
        cin>>a;
        sum[i%k]+=a;
    }
    int mx=0;
    for(int i=1;i<k;i++)
       if(sum[mx]>sum[i])
           mx=i;
    cout<<mx+1;
    return 0;
}


Comments

Submit
0 Comments
More Questions

988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious
1141B - Maximal Continuous Rest
1341A - Nastya and Rice
1133A - Middle of the Contest
385A - Bear and Raspberry
1311B - WeirdSort
1713F - Lost Array
236B - Easy Number Challenge
275A - Lights Out